package com.yl.module.user.listener;

import com.yl.exception.MyException;
import com.yl.module.user.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.event.TransactionPhase;
import org.springframework.transaction.event.TransactionalEventListener;

/**
 *
 * 1. ApplicationListener
 * 2. SmartApplicationListener 实现有序监听
 * 3. @Async实现异步监听
 * @Todo
 * @Author jiangtao
 * @CreateBy 2020-06-08 4:05 PM
 * @UpdateBy jiangtao
 * @Version v1.0
 */
@Component
public class UserRegisterListener implements ApplicationListener<UserRegisterEvent> {

    //@Autowired
    //private IHelpMealUserService hmUserService;

    @Override
    @Async("myTaskExecutor")
    @Transactional(rollbackFor = MyException.class)
    @TransactionalEventListener(phase = TransactionPhase.AFTER_COMMIT)
    public void onApplicationEvent(UserRegisterEvent userRegisterEvent) {
        User user = userRegisterEvent.getUser();

        // 1.添加到 子表

        // 2. 记录到日志

        // 3. 发送通知
    }
}
